package com.yh.correct.service.impl;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yh.correct.dao.IStateChangeMapper;
import com.yh.correct.model.CorrectedPerson;
import com.yh.correct.model.Page;
import com.yh.correct.model.StateChange;
import com.yh.correct.service.IStateChangeService;
/**
 * 矫正状态变更记录服务层接口
 * 
 * @author 王鹏程 
 * @date 2017.03.14
 * @time 13:37
 */
@Service
public class StateChangeServiceImpl implements IStateChangeService {
	/**
	 * 日志记录
	 */
	private static Logger logger = LogManager.getLogger(ExpireServiceImpl.class);
	/**
	 * 注入矫正状态变更记录数据访问层接口
	 */
	@Autowired
	private IStateChangeMapper stateChangeMapper;
	
	/**
	 * 增加矫正状态变更记录
	 * 
	 * @param change
	 * @return
	 * @throws Exception 
	 */
	@Override
	public int addStateChange(StateChange change) {
		logger.debug("增加矫正状态变更记录!");
		return stateChangeMapper.addStateChange(change);
	}
	/**
	 * 删除矫正状态变更记录
	 * 
	 * @param change
	 * @return
	 * @throws Exception 
	 */
	@Override
	public int delStateChange(StateChange change) {
		logger.debug("删除矫正状态变更记录!");
		return stateChangeMapper.delStateChange(change);
	}

	/**
	 * 模糊查询矫正状态变更记录
	 * 
	 * @param condition
	 * @return
	 * @throws Exception 
	 */
	@Override
	public Page queryLikeStateChanges(Map<String, Object> condition) {
		
		Page page=new Page();
		page.setTotalNum(stateChangeMapper.getLikeStateChangesCount(condition));
		int pageSize = Integer.parseInt(String.valueOf(condition.get("pageSize")));
		page.setPageSize(pageSize);
		int curPageNum = Integer.parseInt(String.valueOf(condition.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(stateChangeMapper.getLikeStateChanges(condition));
		logger.debug("模糊查询矫正状态变更记录!");
		return page;
	}
	/**
	 * 查询所有矫正状态变更记录
	 * 
	 * @return
	 * @throws Exception 
	 */
	@Override
	public LinkedList<Map<String, Object>> getAllStateChanges(Map<String,Object> condition) {
		
		return stateChangeMapper.getAllStateChanges(condition);
	}
	/**
	 * 按姓名模糊查询矫正人
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public Page queryLikePersons(Map<String, Object> condition) {
		Page page=new Page();
		page.setTotalNum(stateChangeMapper.getLikePersonsCount(condition));
		int pageSize = Integer.parseInt(String.valueOf(condition.get("pageSize")));
		page.setPageSize(pageSize);
		int curPageNum = Integer.parseInt(String.valueOf(condition.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(stateChangeMapper.getLikePersons(condition));
		logger.debug("模糊查询期满登记!");
		return page;
	}
	/**
	 * 根据id查询矫正人员信息
	 * 
	 * @param correctedperson
	 * @return
	 */
	@Override
	public Map<String, Object> getPersonById(CorrectedPerson correctedperson) {
		Map<String, Object> map = stateChangeMapper.getPersonById(correctedperson);
		return map;
	}
	/**
	 * 修改矫正状态
	 * 
	 * @param correctedperson
	 * @return
	 */
	@Override
	public int editState(CorrectedPerson correctedperson) {
		
		return stateChangeMapper.editState(correctedperson);
	}
}
